package com.mijie.homi.admin.web.user;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mijie.homi.admin.service.user.GradeService;
import com.mijie.homi.common.domain.Grade;

@Controller
@RequestMapping("/grade")
public class GradeController {

	@Autowired
	private GradeService gradeService;
	
	
	@RequestMapping("/list")
	public String list(Model model,HttpServletRequest request){
		List<Grade> list = gradeService.listGrade();
		model.addAttribute("list", list);
		return "grade/list";
	}
	
	@RequestMapping("/create")
	public String create(Model model){
		Integer grade = gradeService.getCurrentHightGrade();
		model.addAttribute("grade",grade);
		return "grade/create";
	}
	
	@RequestMapping("/save")
	public String save(Grade grade,HttpServletRequest request){
		gradeService.addGrade(grade);
		return "redirect:/grade/list.shtml";
	}
	
	@RequestMapping("/edit")
	public String edit(Model model,@ModelAttribute Grade grade){
		model.addAttribute("grade",grade);
		return "grade/edit";
	}
	
	@RequestMapping("/update")
	public String update(Grade grade,HttpServletRequest request){
		gradeService.updateGrade(grade);
		return "redirect:/grade/list.shtml";
	}
	
}
